package com.xrz.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xrz.common.Result;
import com.xrz.dao.GroupMsgDao;
import com.xrz.pojo.vo.GroupMsgVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(value = "群msgController", tags = {"群聊信息操作接口"})
@RestController
@RequestMapping("groupMsg")
public class GroupMsgController {
    @Resource
    GroupMsgDao groupMsgDao;


    //获取某群全部消息
    @ApiOperation(value = "获取某群全部消息")
    @GetMapping("/getGroupMsg/{groupId}")
    public Result<?> getGroupMsg(@PathVariable Integer groupId) {
        List<GroupMsgVo> groupMsgVos=groupMsgDao.selectVoByGroupId(groupId);
        return Result.success(groupMsgVos);
    }

    /**
     * 分页查询
     *
     * @return
     */
    @ApiOperation(value = "获取某群全部消息分页")
    @GetMapping("getGroupMsgList/{groupId}/{page}")
    public Result<?> findUserList(@PathVariable Integer groupId, @PathVariable Integer page) {
        // mysql查询使用limit
        PageHelper.startPage(page, 20); // 底层实现原理采用改写sql语句
        List<GroupMsgVo> groupMsgVos=groupMsgDao.selectVoByGroupId(groupId);
        PageInfo<GroupMsgVo> pageInfoList = new PageInfo<GroupMsgVo>(groupMsgVos);
        return Result.success(pageInfoList);
    }

}
